package com.hks360.car_treasure.util;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.TextView;

import com.baidu.location.LocationClientOption;
import com.hks360.car_treasure.common.BaiduMapConfig;
import com.hks360.library.util.CommonUtil;

import java.text.DecimalFormat;

/**
 * Created by xiaote on 2016/3/16.
 */
public class MyUtil {
    public static String getVersionInfo(Context context,String packageName) {
        String[] version = CommonUtil.getVersion(context, packageName);
        if(version != null) {
            return "(版本号:" + version[0] + ",版本名称:" + version[1] + ")";
        }
        return "";
    }

    public static LocationClientOption getLationClientOption() {
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(BaiduMapConfig.OPEN_GPS);// 打开gps
        option.setCoorType(BaiduMapConfig.COOR_TYPE); // 设置坐标类型
        option.setScanSpan(BaiduMapConfig.SCAN_SPAN);
        return option;
    }

    public static void setDrawableTop(Context context, TextView tv, int resId) {
        Drawable drawable = context.getResources().getDrawable(resId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tv.setCompoundDrawables(null, drawable, null, null);
    }

    public static String getCommandEngin(boolean enginClick) {
        return enginClick ? "EngineON" : "EngineOFF";
    }

    public static String getCommandLock(boolean lockClick) {
        return lockClick ? "LockON" : "LockOFF";
    }

    public static String getCommandFrontDefrost(boolean isClick) {
        return isClick ? "FrontDefrostON" : "FrontDefrostOFF";
    }

    public static String getCommandRearDefrost(boolean isClick) {
        return isClick ? "RearDefrostON" : "RearDefrostOFF";
    }

    public static String getCommandSeatHeat(boolean isClick) {
        return isClick ? "SeatHeatON" : "SeatHeatOFF";
    }

    public static String getCommandAc(int flag) {
        switch (flag) {
            case -1:
                return "ColdLower";
            case -2:
                return "ColdMiddle";
            case -3:
                return "ColdHigh";
            case 0:
                return "ACOFF";
            case 1:
                return "WarmLower";
            case 2:
                return "WarmMiddle";
            case 3:
                return "WarmHigh";
        }
        return "ACOFF";
    }

    public static double getBaiduLatitudeOrLongitude(String str) {
        if (CommonUtil.isEmptyStr(str) || str.startsWith("0")) {
            return 0;
        }
        DecimalFormat format = new DecimalFormat("0.000000");
        double value = 0;
        if(str.length() == 8){
            double du = Double.parseDouble(str.substring(0,2));
//            double fen = Double.parseDouble(str.substring(2,4));
            double sec = Double.parseDouble(str.substring(2,str.length()));
            value = du +  sec / 600000;
        }else if(str.length() == 9){
            double du = Double.parseDouble(str.substring(0,3));
//            double fen = Double.parseDouble(str.substring(3,5));
            double sec = Double.parseDouble(str.substring(3,str.length()));
            value = du  + sec / 600000;
        }
        return value;
    }

}
